function view_approved_payment(){
	queryURL(BASE_URI+"admin/dataman/payment/offline_payment2");
}

function view_completed_cod_payment(){
	queryURL(BASE_URI+"admin/dataman/payment/cod_completed");
}

function view_cancelled_cod_payment(){
	queryURL(BASE_URI+"admin/dataman/payment/cod_cancelled");
}

function approve_item(id){
	jQuery('#loader_image_'+id).show();
	jQuery.post(BASE_URI+'admin/dataman/payment/approve_payment',{id:id},function(res){
		reload();
	});
}

function delete_item(id){
	if(confirm("Are you sure want to delete this item?")){
		jQuery('#loader_image_'+id).show();
		jQuery.post(BASE_URI+'admin/dataman/payment/delete_payment',{id:id},function(res){
			reload();
		});
	}
}

function approve_cod_item(id){
	jQuery('#loader_image_'+id).show();
	jQuery.post(BASE_URI+'admin/dataman/payment/approve_cod_item',{id:id},function(res){
		reload();
	});
}

function cancel_cod_item(id){
	jQuery('#loader_image_'+id).show();
	jQuery.post(BASE_URI+'admin/dataman/payment/cancel_cod_item',{id:id},function(res){
		reload();
	});
}

function dispatch_cod_item(id){
	jQuery('#loader_image_'+id).show();
	jQuery.post(BASE_URI+'admin/dataman/payment/dispatch_cod_item',{id:id},function(res){
		reload();
	});
}

function edit_item(id){
	jQuery.post(BASE_URI+'admin/dataman/payment/view_edit_payment',{id:id},function(res){
		jQuery('#dialog').html(res);
		jQuery('#dialog').dialog(
			{
				 width: 650,
				 resizable: false,
				 height:300,
				 title: 'View payment details' 
			}
		);
	});	
}

jQuery(document).ready(function() {
	jQuery( "#fromDate,#toDate" ).datepicker({
			changeMonth: true,
			changeYear: true,
			dateFormat: 'mm/dd/yy'
		});
	jQuery( "#username" ).autocomplete({
			 source: username
		});	

	var optionsEmailSubs = { 
		beforeSubmit:beforeSubmitPayment,   
		success:afterSubmitPayment
	};	
	
	jQuery("#edit_payment_submit").live("submit",function(e){
		e.preventDefault(); // <-- important
		jQuery(this).ajaxSubmit(optionsEmailSubs);
		return false;
	});	
	
});


function afterSubmitPayment(responseText, statusText, xhr, $form){
	jQuery('#loader_image').hide();	
	 
	if(responseText == 'ok'){
		jQuery('#dialog').dialog('close');
		reload();
	}else{
		alert(responseText);
	}
} 

function beforeSubmitPayment(formData, jqForm, options){
	jQuery('#loader_image').show();
	return true;	
}
